import pandas as pd
import os
import re


def main():
	source_dir = r"Z:\冯洋洋\解译结果2"
	txt_paths = [
		os.path.join(source_dir, file_name)
		for file_name in os.listdir(source_dir)
	]
	index = [f"{i}" for i in range(len(txt_paths))]
	column_count = 0
	for txt_path in txt_paths:
		with open(txt_path, "r", encoding='utf-8') as txt_file:
			centont = txt_file.read()
			infos = centont.split("\n")
			if column_count < len(infos):
				column_count = len(infos)
	columns = [f"{column}" for column in range(column_count)]
	dataframe = pd.DataFrame(columns=columns, index=index)
	for txt_path in txt_paths:
		file_name = os.path.basename(txt_path)
		ind = file_name.split("_")[0]
		with open(txt_path, "r", encoding='utf-8') as txt_file:
			centont = txt_file.read()
			infos = centont.split("\n")
			for column, info in enumerate(infos):
				print(column, ind, info)
				dataframe[f"{column}"][f"{ind}"] = info
	print(dataframe)
	dataframe.to_excel(r"E:\解译结果2.xlsx")
	return


if __name__ == "__main__":
	main()

